package com.jswdwsx.esign.entity

import com.vladmihalcea.hibernate.type.json.JsonStringType
import com.jswdwsx.esign.cloud.enums.FlowStatusEnum
import com.jswdwsx.esign.protocol.response.Doc
import org.hibernate.annotations.DynamicInsert
import org.hibernate.annotations.DynamicUpdate
import org.hibernate.annotations.Type
import org.hibernate.annotations.TypeDef
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime
import javax.persistence.*

@Entity
@EntityListeners(AuditingEntityListener::class)
@DynamicInsert
@DynamicUpdate
@TypeDef(name = "json", typeClass = JsonStringType::class)
@Table(name = "flow")
class FlowPO(

    @Id
    var requestId: String? = null,

    @Column(name = "esign_flow_id")
    var esignFlowId: String,                           // e签宝flow_id

    @Column(name = "status")
    @Enumerated(EnumType.STRING)
    var status: FlowStatusEnum,

    @Column(name = "version")
    var version: Int,

    @Column(name = "oss_file_url")
    @Type(type = "json")
    var ossFileUrl: List<Doc>?,                      // 阿里云存储文件的url

    @Column(name = "sign_url")
    var signUrl: String? = null,                            // 协议签署的url

    @CreatedDate
    @Column(name = "created_time")
    var createdTime: LocalDateTime? = null,

    @LastModifiedDate
    @Column(name = "updated_time")
    var updatedTime: LocalDateTime? = null,

    @OneToOne(fetch = FetchType.LAZY)
    @MapsId                                         // 由于一对一关系，直接将request的id作为flow的id
    val request: RequestPO


)